package com.itstudy.springbootreqresp.controller;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import com.itstudy.springbootreqresp.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Arrays;
import java.util.Locale;
//@RestController
//public class RequestController {
//    @RequestMapping("/simpleParam")
//    public  String simpleParam(HttpServletRequest request){
//        String name = request.getParameter("name");
//        String ageStr=request.getParameter("age");
//        int age=Integer.parseInt(ageStr);
//        System.out.println(name+"---"+age);
//        return "success";
//    }
//
//}

//springboot方式,直接接收参数
//@RestController
//public class RequestController {
//    @RequestMapping("/simpleParam")
//    public  String simpleParam(String name,Integer age){
//        System.out.println(name+"---"+age);
//        return "success";
//    }
//
//}


@RestController
public class RequestController {
    //@RequestParam注解形式，可不与传递参数名保持一致
    @RequestMapping("/simpleParam")
    public  String simpleParam(@RequestParam("name") String username, Integer age){
        System.out.println(username+"---"+age);
        return "success";
    }

    //实体参数,参数包含在java类里面
  @RequestMapping("/simplePojo")
    public String simplePojo(User user){
        System.out.println(user);
        return "success";
    }

    //复杂参数，参数包含在两个的java类里面
    @RequestMapping("/complexPojo")
    public String complexPojo(User user){
        System.out.println(user);
        return "success";
    }


//    使用数组型接收参数
    @RequestMapping("/arrayParam")
    public String arrayParam(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return "success";
    }

    //    使用集合型接收参数
    @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> hobby){
        System.out.println(hobby);
        return "success";
    }

    //    时间日期类型接收参数
    @RequestMapping("/dateParam")
    public String dateParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime updateTime){
        System.out.println(updateTime);
        return "success";
    }

    //    JSON类型接收参数:body raw json
    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user){
        System.out.println(user);
        return "success";
    }
    //    路径参数
    @RequestMapping("/pathParam/{id}/{name}")
    public String pathParam(@PathVariable Integer id,@PathVariable String name){
        System.out.println(id+"--"+name);
        return "success";
    }


}


